import { lazy } from 'react'
import { createBrowserRouter } from 'react-router-dom'

import AuthRoute from '@/components/AuthRoute'
import Home from '@/views/Home'
import Article from '@/views/Article'
import Publish from '@/views/Publish'

const Login = lazy(() => import('@/views/Login'))
const Layout = lazy(() => import('@/views/Layout'))

const router = createBrowserRouter([
  {
    path: '/',
    element: (
      <AuthRoute>
        <Layout />
      </AuthRoute>
    ),
    children: [
      {
        index: true,
        element: <Home />
      },
      {
        path: '/article',
        element: <Article />
      },
      {
        path: '/publish',
        element: <Publish />
      }
    ]
  },
  {
    path: '/login',
    element: <Login />
  }
])

export default router
